PHP + MYSQL create table [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
SO, I want to create a pretty big mysql table that should save all of the squares of a chess board and their value, I'm using a PHP for() since it has 64 squares.
This always gives me 'not working'
<?php
mysql_connect('localhost','pierostesting','');
mysql_select_db('my_pierostesting');
$query="CREATE TABLE board (";
for($i=0;$i<63;$i++){
$query .= "i".$i." INT(1) NOT NULL,";
}
$query .="turno BOOL";
if (mysql_query($query)){
echo 'working';
}else echo 'not working'; ?>

I'm an idiot, didn't close the bracket.

try echoing out your complete SQL string, then use phpMyAdmin and see if the sql string actually works, or if it throws errors. You may have a sql syntax error.
If it does work, make sure your connection variables are correct (host, db name, username, password)
that should get you close to the answer.

Related

Php, SQL not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So lately I've tried my attempt at SQL, and PHP, and other such, I've come to a problem that of which being: INSERT INTO, just can't seem to work for me. Here's what I have in the PHP file:
$sql = "INSERT INTO forum(USERID, FN, LN, Email) VALUES (NULL,'".$_POST['FN']."', '".$_POST['LN']."', '".$_POST['Email']."';";
This string works, however, I get This error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
Would anyone be able to provide info on this?
You must close the parenthesis:
$sql = "INSERT INTO forum(USERID, FN, LN, Email) VALUES (NULL,'".$_POST['FN']."', '".$_POST['LN']."', '".$_POST['Email']."');";

Update record number unexpectedly fails [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am trying to get this to update a record and was wondering why I cant get this to work?
I can write a new record no problem but the update doesn't work; is it something simply I am missing?
else {
echo "ID NOT EMPTY-";
//---inside else statement shows this echo and the $id number printed on screen WHERE should have varible $ID but I changed it to debug
echo "$id";
$SQLstring3 = "UPDATE $Tablename SET(blank='1') WHERE(id='5')";
$QueryResult = #mysql_query($SQLstring3, $DBConnect);
}
I think the problem might be the way you are using SET and WHERE. Putting them the parentheses () immediately following them might make them seem like a MYSQL function, which it tries to execute. What you have is this:
"UPDATE $Tablename SET(blank='1') WHERE(id='5')";
Try removing the parentheses:
"UPDATE $Tablename SET blank='1' WHERE id='5'";

Php help find where is syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes===".$card['id']."") as $kat){
echo (kat['id_categories']);
}
table cols and values are all matched, something is wrong in this part of code
I tried adding $ before kat and using only one "=", sill doesnt work
NEW LINK
http://pastebin.com/RPK7vEaJ
this
where id_kartes===".$card['id']."
would be
where id_kartes=".$card['id']."
and missing $
echo $kat['id_categories'];
so full code :-
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes='".$card['id']."'") as $kat){
echo $kat['id_categories'];
}
best practice if you store your query result in a variable and loop over this variable.
foreach($db->fetch_array("SELECT id_categories FROM csn_categories_join_kartes where id_kartes=".$card['id']."") as $kat)

PHP stops after faile PDO query [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I am running the below code and know that this is the suspect peice as I have placed an echo above and below it. The first runs fine but the second does not.
If I change the query to something like "show tables" it will run but I cannot see what if anything is wrong with this. I have checked reserved words and syntax. Am I missing something obvious!
try
{
$sth = $dbh->prepare('SELECT COUNT(*) AS val FROM users WHERE username=:user');
$sth->binvalue('user',$_POST['user']);
$sth->execute();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
There is a type error:
instead of
$sth->binvalue('user',$_POST['user']);
Try
$sth->bindvalue('user',$_POST['user']);
^
$sth->binvalue('user',$_POST['user']);
should be
$sth->bindValue(':user',$_POST['user']);
Notice both the bindValue and the :user

Unable to insert data php mysql - integer [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am unable to insert integer data from insert statement.
$value = $_POST[from];
$query = mysql_query("INSERT INTO trip(tripid,from)VALUES(NULL, $value)");
Here from is integer value, but i am getting syntax error as :
You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near'from)VALUES(NULL, 1)'` at line 1.
from is Reserved Words in MySQL http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html
try this
mysql_query("INSERT INTO trip(tripid,`from`)VALUES(NULL, $value)");

Categories