Jump to content

Recommended Posts

Hello Everyone

 

for some reason, when insert the character data into in the database table, it becomes integers (0,0,0,0,0,0)

is there anything wrong with my code, which converts my character data to integers?

 

all the integers retrieved are VARCHARS

 

 

<?php

include "connect.php";

//get user variables
$web_namex = $_POST['web_name'];
$folderx = $_POST['folder'];
$image_folx = $_POST['image_fol'];
$css_filex = $_POST['css_file'];
$js_filex = $_POST['js_file'];
$divx = $_POST['div'];

//input user vars
$preset_table = mysql_query("
INSERT INTO stageone (
`web_name` ,
`folder` ,
`image_fol` ,
`css_file` ,
`js_file` ,
`div`
)
VALUES (`web_name` = '$web_namex', `folder` = '$folderx', `image_fol` = '$image_folx', `css_file` = '$css_filex', `js_file` = '$js_filex', `div` = '$divx')");

//testing input (presets)
if ($preset_table)
{
	if($div = "yes")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo1.php");
	}
	if($div = "no")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo2.php");
	}
	else
	{
		echo "Redirection failed.";
	}	
}
//testing not successful
else
{
echo "Input Error with user Vars.";
}

//close connection
?>

Link to comment
https://forums.phpfreaks.com/topic/105077-inserting-characters-into-databases/
Share on other sites

Im not sure that query works as the correct syntax of the insert statement should be:

 

INSERT INTO stageone (web_name, folder, image_fo, css_file, js_file, div)
VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')

 

Never tried it that way as maybe it works, but just wanted to mention it out.

Thank you for your support - it seems that I am still having the same problem over and over again.

 

Please look over why the data keeps on changing to integers when they're characters, thank you.

 

HTML file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Webgen 2.0</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<center>
<b>Webgen 2.0</b><br>
[stage 1]

<form name="Stage One" method="post" action="stageone2.php">

<p>
   <input name="web_name" type="text" id="web_name" value="Website Name">
</p>
<p>    
   <input name="folder" type="text" id="folder" value="Folder Name">
</p>
<p>
  <input name="image_fol" type="text" id="image_fol" value="Image Location">
</p>
<p>
  <label>CSS file 
  <select name="css_file" id="select">
    <option value="0">Yes</option>
    <option value="1">No</option>
  </select>
  </label>
  </p>
<p>JS File
  <label>
  <select name="js_file" id="select2">
    <option value="0">Yes</option>
    <option value="1">No</option>
  </select>
  </label>
  </p>
<p>Divided Layout
  <label>
  <select name="div" id="select3">
    <option value="0">Yes</option>
    <option value="1">No</option>
  </select>
  </label>
</p>
<p>
  <input type="submit" name="Submit" value="Submit">
</p>
</form>


</center>
</body>
</html>

 

PHP file

<?php

include "connect.php";

//get user variables
$web_namex = $_POST['web_name'];
$folderx = $_POST['folder'];
$image_folx = $_POST['image_fol'];
$css_filex = $_POST['css_file'];
$js_filex = $_POST['js_file'];
$divx = $_POST['div'];

//input user vars
$preset_table = mysql_query("
INSERT INTO stageone (
`web_name` ,
`folder` ,
`image_fol` ,
`css_file` ,
`js_file` ,
`div`
)
VALUES (`web_name` = '$web_namex', `folder` = '$folderx', `image_fol` = '$image_folx', `css_file` = '$css_filex', `js_file` = '$js_filex', `div` = '$divx')");

//testing input (presets)
if ($preset_table)
{
	if($div = "yes")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo1.php");
	}
	if($div = "no")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo2.php");
	}
	else
	{
		echo "Redirection failed.";
	}	
}
//testing not successful
else
{
echo "Input Error with user Vars.";
}

//close connection
?>

 

structure.JPG

Im not sure that query works as the correct syntax of the insert statement should be:

 

INSERT INTO stageone (web_name, folder, image_fo, css_file, js_file, div)
VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')

 

Never tried it that way as maybe it works, but just wanted to mention it out.

Just to be sure, i made a test with the way u wrote the query and its happening the exact thing its happening to u. Im getting 0 in varchar(10) fields. Write your query as i suggested in my previous post:

 

$preset_table = mysql_query("INSERT INTO stageone (web_name, folder, image_fol, css_file, js_file, div)
                             VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')");

 

U dont need to respecify the columns in VALUES(). Take this example:

 

INSERT INTO table (col1, col2, col2) VALUES (col1value, col2value, col3value)

 

col1value corresponds to col1, col2value corresponds to col2 and so on.

http://www.webstood.com/webgen/stageone1.html

 

As you can see, it's returning an error.

 

[stageone2.php]

<?php

include "connect.php";

//get user variables
$web_namex = $_POST['web_name'];
$folderx = $_POST['folder'];
$image_folx = $_POST['image_fol'];
$css_filex = $_POST['css_file'];
$js_filex = $_POST['js_file'];
$divx = $_POST['div'];

//input user vars
$preset_table = mysql_query("INSERT INTO stageone (web_name, folder, image_fol, css_file, js_file, div)
                              VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')");

//testing input (presets)
if ($preset_table)
{
	if($div = "yes")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo1.php");
	}
	if($div = "no")
	{
		header("Location: http://www.webstood.com/webgen/stagetwo2.php");
	}
	else
	{
		echo "Redirection failed.";
	}	
}
//testing not successful
else
{
echo "Input Error with user Vars.";
}

//close connection
?>

try:

 

$preset_table = mysql_query("INSERT INTO stageone (`web_name`, `folder`, `image_fol`, `css_file`, `js_file`, `div`) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')");

 

If that fails, pull the query out of the mysql_query block and echo it out to see exactly what the query is (after the variables are parsed).  Post this result.  It could an unsanitary sql string (stray ; or ' in one of the variables.

 

$query = "INSERT INTO stageone (`web_name`, `folder`, `image_fol`, `css_file`, `js_file`, `div`) VALUES ('$web_namex', '$folderx', '$image_folx', '$css_filex', '$js_filex', '$divx')";
echo $query;
$preset_table = mysql_query($query);

 

Since you are using phpmyadmin, try to generate the query like in the second block, then copy paste it into the "sql" tab in phpmyadmin.  It usually does a good job of pointing out the syntax errors. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.