PHP to input email to database [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
This is the site that I am trying to create the script for http://facechat.louisdickinson.com/
The idea is people can save there email to my database, and another button called "Start Call" will randomly select a email and call it using:
facetime://email#email.com
Effectively this will create a "omegle" style web-based facetime chat site.
I am new to MySQL and PHP and don't know where to start, any help will be appreciated!

I don't know, what kind of help do you need.. First of all, you should have a php script, witch can take the posted name/e-mail pair.
In this script, you should sanitize the posted values, than you can add it to your database with the following:
$query = "INSERT INTO <tableName> (`name`, `e-mail`) VALUES ( '".$postedName."', '".$postedMail."' )";
On button press, you should have another php script, for selecting the random e-mail:
$query = "SELECT COUNT(*) FROM <tableName>";
$max should be the query result.
$random = rand( 0 , $max - 1 );
$query = "SELECT `e-mail` FROM <tableName>" LIMIT $random, 1";
With this query you got a random e-mail.
Do you need more exact code? Please be more exact on what you need!
Kind regards,
hotzu

In php:
mysql_connect("host", "user", "password") or die(mysql_error());
mysql_selectdb("database"); // '' for an auto increment column
mysql_query("INSERT INTO TABLE VALUES ('$email', ''));
And for more info http://www.w3schools.com/php/php_mysql_intro.asp

Related

Using PHP?= to navigate between pages [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am able to navigation between a php page using ID but not using project name. Can you only use an number and not characters?
Works
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE id=$id";
'.$row['project'].'
page url: https://example.com/project.php?id=1
Doesn't work
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE project=$project";
'.$row['project'].'
page url: https://example.com/project.php?project=Test
Thanks for the help!
MySQL uses single or double quotes for strings. Your second query puts string to a query, resulting in invalid query.
This is not a valid SQL query:
SELECT `name` FROM `cats` WHERE `breed` = ordinary cat
But this is:
SELECT `name` FROM `cats` WHERE `breed` = 'ordinary cat'
Of note, be careful with using any input (including query string) in your query like you did. You should use prepared statement instead to safely escape that string for your query.

MySQL Database table from PHP code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have attempted to create a mysql query to create the database schema but with no success, here is the php code that get data from the database, could you please help me create a mysql script that will create the database tables?
here is the php script:
foreach($string["statuses"] as $status) {
$selectSQL = 'SELECT * FROM twitter WHERE t_id="'.$status["id"].'" ';
$queryset = '';
$queryset = $mysqli->query ($selectSQL);
if(mysqli_num_rows($queryset)==0)
{
$text = mysqli_real_escape_string($mysqli, $status["text"]);
$loc = mysqli_real_escape_string($mysqli, $status["user"]["location"]);
$user_id = mysqli_real_escape_string($mysqli, $status["user"]["id"]);
$app = mysqli_real_escape_string($mysqli, $status["source"]);
$img = mysqli_real_escape_string($mysqli, $status["user"]["profile_image_url"]);
$retweet = mysqli_real_escape_string($mysqli, $status["retweet_count"]);
$favorite = mysqli_real_escape_string($mysqli, $status["favorite_count"]);
$mysqli->query('INSERT INTO `twitter` VALUES (NULL,"'.$status['id'].'","'.$text.'","'.$status['created_at'].'","'.$loc.'","'.$user_id.'","'.$app.'","'.$img.'","'.$retweet.'","'.$favorite.'")');
}
}
First, some nomenclature;
This:
$mysqli->query('INSERT INTO twitter VALUES (NULL,"'.$status['id'].'","'.$text.'","'.$status['created_at'].'","'.$loc.'","'.$user_id.'","'.$app.'","'.$img.'","'.$retweet.'","'.$favorite.'")');
is a command to place data into a table that already EXISTS, unless you want a table of PHP MySQL query strings, which I'm thinking you do not.
In either case, you will need to read up on the CREATE TABLE section of MySQL, and learn how to create a table in MySQL. Your question is unclear, and no one will just do the work for you here. Stack Overflow is a learning place.
If you want to have an elephant circus, you'll need to know about elephants...or hire an elephant trainer.
Once you understand how to create the table, you can learn how to read (query) it, insert into it (as this query does), remove entries, alter the table structures, and more. This will require some PHP knowledge, unless you choose another scripting language, like Ruby or Perl, and you'll want to have a pleasant database manager to view your db; my personal favorite is Adminer, available at
http://adminer.org
There are others, which you can Google easily. Good luck with your work.
Check out this link.
https://www.w3schools.com/php/php_mysql_create_table.asp
You have to write the SQL yourself though.

is it possible to load unique item or one of a kind item from sql using php? (check image) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
The image above is my sql database. what I want to do is load the names and echo in json but the thing is though, I want to show one of each name. Like see how there are 4 assassinshadow entries? I want php to echo only one of em. not making much sense am I? haha
You can use DISTINCT in your mysql query:
$mysqli = mysqli_connect("example.com", "user", "password", "database");
$query = "SELECT DISTINCT name from yourtable";
$res = mysqli_query($mysqli, $query);
$row = mysqli_fetch_assoc($res);
Two ways to do that:
SELECT distinct name FROM my_table
or
SELECT name FROM my_table group by name

INSERT INTO-Statement with PHP-Variable and SELECT-Statement [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I´m trying to insert a current SELECT-Statement into an Database table with an PHP-variable. It works by this way without the variable:
mysql_query("INSERT INTO table (column) SELECT column FROM table1");
Did anyone have a idea how I can fix it?
PHP: 5.3.10 and mysql-databse
try this
$sample="SELECT column FROM table1"; // your select query
$query="INSERT INTO `table` (column) $sample";
mysqli_query('database connection code',$query);
Let me know if any problem arises.
You can use mysql_insert_id() to get the last inserted ID value and try insert query separately.
<?PHP
$lastId = mysql_insert_id();
$query = mysql_query("Your Select Query with $lastId");
?>

How to Get Mysql Field Data [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a registration system , username, password, email id are stored in a table, how can i export or get all email ids of all my registered users in Phpmyadmin itself (or any other way).
Run query
select email_id from users
Then use export feature of phpmyadmin.After you run the query, click the export link and you can export the query result in many different formats (e.g CSV, Excel, Word...)
Please change table and column names according to you.
try this>>
$sql = "select email_id from table_name";
$result = mysql_query($sql);
$email_collector = array();
while( $row = mysql_fetch_assoc($result) ){
//store email in array
$email_collector[] = $row['email_id'];
}
print_r($email_collector);
Change email_id and table_name according to your database
If you want to get list of users and their email in a text file try the below query
SELECT username, email INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM table2;

Categories